package development.group;

import state.GameForm;
import state.GameGlobal;
import state.Graphics;
import state.GroupForm;
import state.component.Event;
import state.component.EventListener;
import state.component.MultiTab;
import state.util.Hashtable;
import development.Constants;
import development.DrawUtils;
import development.FrmChat;
import development.FrmDownloadResource;
import development.FrmListFreeUser;
import development.FrmListTable;
import development.Global;

public class FrmGroupListTableFreeUserChat extends GroupForm implements EventListener {
  private MultiTab multiTab;
  private static GameForm singleton;
  public static GameForm backForm;
  
  public static GameForm instance() {
    if (singleton == null) {
      singleton = new FrmGroupListTableFreeUserChat();
    }
    return singleton;
  }
  
  public void init(Hashtable parameters) {
    multiTab = new MultiTab(this, Constants.SCREEN_WIDTH, Constants.SCREEN_HEIGHT);
    multiTab.addTab("DS Bàn", FrmListTable.instance(), parameters);
    multiTab.addTab("Người chơi", FrmListFreeUser.instance(), parameters);
    multiTab.addTab("Chat", FrmChat.instance(), parameters);
    multiTab.setStyle(Constants.MULTI_TAB_STYLE);
    multiTab.selectTab(0);
  }
  
  public static void setTab(int index) {
    FrmGroupListTableFreeUserChat frmFriendAndTop = (FrmGroupListTableFreeUserChat) FrmGroupListTableFreeUserChat.instance();
    MultiTab multiTab = frmFriendAndTop.getMultiTab();
    if (multiTab != null) {
      multiTab.selectTab(index);
    }
  }
  
  public MultiTab getMultiTab() {
    return multiTab;
  }
  
  public void draw(Graphics g) {
    DrawUtils.drawBackground(g);
  }
  
  public void onActionPerform(Event event) {
  }
  
  public void goBack() {
    if (backForm != null) {
      Global.nextState(backForm, null);
      backForm = null;
    } else {
      if (Global.systemCanvas.lastState instanceof FrmDownloadResource) {
        GameGlobal.nextState(FrmGroupMenu.instance(), null);
      } else {
        GameGlobal.nextState(Global.systemCanvas.lastState, null);
      }
    }
  }
  
  public void destroy() {
    multiTab.detroy();
    multiTab = null;
    FrmListTable.instance().detroyAll();
    FrmListFreeUser.instance().detroyAll();
  }
}
